<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp" />
 <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="css/style.css"/>       
        <link href="assets/css/codemirror.css" rel="stylesheet">
        <link rel="stylesheet" href="assets/css/ace.min.css" />
        <link rel="stylesheet" href="font/css/font-awesome.min.css" />
        <!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->
		<script src="js/jquery-1.9.1.min.js"></script>
		<script src="assets/layer/layer.js" type="text/javascript" ></script>
        <script src="assets/laydate/laydate.js" type="text/javascript"></script>  
        <script src="assets/js/bootstrap.min.js"></script>
		<script src="assets/js/typeahead-bs2.min.js"></script>           	
		<script src="assets/js/jquery.dataTables.min.js"></script>
		<script src="assets/js/jquery.dataTables.bootstrap.js"></script>
                      
<title>个人信息管理</title>
</head>

<body>
<div class="clearfix">
 <div class="admin_info_style">
   <div class="admin_modify_style" id="Personal">
     <div class="type_title">管理员信息 </div>
      <div class="xinxi">
        <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >用户名： </label>
          <div class="col-sm-9"><input type="text" name="用户名" id="website-title" value="张小泉" class="col-xs-7 text_info" disabled="disabled">
          &nbsp;&nbsp;&nbsp;<a href="javascript:" onclick="change_Password()" class="btn btn-warning btn-xs">修改密码</a></div>
          
          </div>
          <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >性别： </label>
          <div class="col-sm-9">
          <span class="sex">男</span>
            <div class="add_sex">
<!--            <label><input name="form-field-radio" type="radio" class="ace" checked="checked"><span class="lbl">保密</span></label>&nbsp;&nbsp;-->
            <label><input name="form-field-radio" type="radio" class="ace" value="1"><span class="lbl">男</span></label>&nbsp;&nbsp;
            <label><input name="form-field-radio" type="radio" class="ace" value="0"><span class="lbl">女</span></label>
            </div>
           </div>
          </div>
          <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >ID: </label>
              <div class="col-sm-9" > <span id="managerId">124435</span></div>
          </div>
          <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >移动电话： </label>
          <div class="col-sm-9"><input type="text" name="移动电话" id="iphone" value="13567878908" class="col-xs-7 text_info" disabled="disabled"></div>
          </div>
          <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >电子邮箱： </label>
          <div class="col-sm-9"><input type="text" name="电子邮箱" id="email" value="567890@qq.com" class="col-xs-7 text_info" disabled="disabled" style="width: 170px"></div>
          </div>
          <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >QQ： </label>
          <div class="col-sm-9"><input type="text" name="QQ"  value="456789787" class="col-xs-7 text_info" disabled="disabled"> </div>
          </div>
           <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >权限： </label>
          <div class="col-sm-9" > <span id="type">普通管理员</span></div>
          </div>
           <div class="form-group"><label class="col-sm-3 control-label no-padding-right" >注册时间： </label>
          <div class="col-sm-9" > <span id="time">2016-7-5</span></div>
          </div>
           <div class="Button_operation clearfix" id="saveBox">
				<button onclick="modify();" class="btn btn-danger radius" type="submit">修改信息</button>				
				<button onclick="save_info();" class="btn btn-success radius" type="button" id="saveBtn" >保存修改</button>
			</div>
            </div>
    </div>
    <div class="recording_style">
    <div class="type_title">超级管理员登录记录 </div>
    <div class="recording_list">
     <table class="table table-border table-bordered table-bg table-hover table-sort" id="sample-table">
    <thead>
      <tr class="text-c">
<!--        <th width="25"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>-->
        <th width="80">ID</th>
          <th width="10%">用户名</th>
          <!--        <th width="100">类型</th>-->
          <th>内容</th>
          <!--        <th width="17%">登录地点</th>-->
<!--        <th width="120">客户端IP</th>-->
        <th width="150">时间</th>
      </tr>
    </thead>
    <tbody id="infoTbody">
    </tbody>
  </table>
    </div>
        <div id="pageBox" style="margin-top: 5%">
            <button id="upPage" onclick="up()" style="margin-left: 42%">上一页</button>
            <input type="text" id="page" style="width: 35px;text-align: center"/>&emsp;/<input type="text" id="total" style="width: 35px;text-align: center" disabled="disabled"/>
            <button id="nextPage" onclick="next()">下一页</button>
        </div>
    </div>
 </div>
</div>
 <!--修改密码样式-->
         <div class="change_Pass_style" id="change_Pass">
            <ul class="xg_style">
             <li><label class="label_name">原&nbsp;&nbsp;密&nbsp;码</label><input name="原密码" type="password" class="" id="password"></li>
             <li><label class="label_name">新&nbsp;&nbsp;密&nbsp;码</label><input name="新密码" type="password" class="" id="Nes_pas"></li>
             <li><label class="label_name">确认密码</label><input name="再次确认密码" type="password" class="" id="c_mew_pas"></li>
              
            </ul>
<!--            <div class="center"> <button class="btn btn-primary" type="button" id="submit">确认修改</button></div>-->
         </div>
</body>
</html>
<script>
    //超级管理员信息展示
    var mangerId = $("#managerId");
    var username = $("input[name='用户名']");
    var sex = $("input[name=form-field-radio]");
    var iphone = $("input[name='移动电话']");
    var sex = $(".sex");
    var email = $("input[name='电子邮箱']");
    var qq = $("input[name=QQ]");
    var type = $("#type");
    var time = $("#time");
    $.ajax({
        url: "http://localhost:8080/SnacksShop/supManager.do?type=supManagerInfo",
        type: "post",
        data:{

        },
        crossDomain: true,
        xhrFields: {
            withCredentials: true
        },
        type: "post",
        success:function (data){
            var obj = JSON.parse(data);
            // console.log(obj);
            if (obj.manager.message == '200'){
                var manager = obj.manager.object;
                mangerId.text(manager.managerId);
                username.val(manager.managerName);
                if (manager.manageSex == '1'){
                    $("input[value='1']").attr("checked","checked");
                    sex.text("男");
                }else {
                    $("input[value='0']").attr("checked","checked");
                    sex.text("女");
                }
                iphone.val(manager.manageIphone);
                email.val(manager.manageEmail);
                qq.val(manager.manageQq);
                if (manager.manageType == '1'){
                    type.text("超级管理员");
                }else {
                    type.text("普通管理员");
                }
                time.text(new Date(manager.manageTime.time).toLocaleDateString());
            }
        },
        error:function (data){

        }
    });
 //按钮点击事件
function modify(){
	 $('.text_info').attr("disabled", false);
	 $('.text_info').addClass("add");
	  $('#Personal').find('.xinxi').addClass("hover");
	  $('#Personal').find('.btn-success').css({'display':'block'});

	};
function save_info(){
	    var num=0;
		 var str="";
     $(".xinxi input[type$='text']").each(function(n){
          if($(this).val()=="") {
			   layer.alert(str+=""+$(this).attr("name")+"不能为空！\r\n",{
                title: '提示框',				
				icon:0,								
          }); 
		    num++;
            return false;            
          }
		 });
    var usernameExist = $("#website-title").attr("value");
    var iphoneExist = $("#iphone").attr("value");
    var emailExist = $("#email").attr("value");
    if (usernameExist == 'true'){
        layer.alert("用户名已存在 \r\n",{
            title: '提示框',
            icon:0,
        });
    }
    if (iphoneExist == 'true'){
        layer.alert("手机号码已存在 \r\n",{
            title: '提示框',
            icon:0,
        });
    }
    if (emailExist == 'true'){
        layer.alert("邮箱已存在 \r\n",{
            title: '提示框',
            icon:0,
        });
    }
    if (usernameExist == 'true'|| iphoneExist == 'true' || emailExist == 'true'){
        return false;
    }
		  if(num>0){
		      return false;
		  } else{
		      var username = $("#website-title").val();
		      var sex = $("input[name=form-field-radio]:checked").val();
		      var iphone = $("#iphone").val();
		      var email = $("#email").val();
		      var qq = $("input[name=QQ]").val();
              $.ajax({
                  url: "http://localhost:8080/SnacksShop/supManager.do?type=updateSupManager",
                  type: "post",
                  data:{
                      username:username,
                      sex:sex,
                      iphone:iphone,
                      email:email,
                      qq:qq
                  },
                  crossDomain: true,
                  xhrFields: {
                      withCredentials: true
                  },
                  type: "post",
                  success:function (data){
                      var obj = JSON.parse(data);
                      console.log(obj);
                      if (obj.status == '200'){
                          layer.alert('修改成功！',{
                              title: '提示框',
                              icon:1,
                          });
                      }else {
                          layer.alert('修改失败！',{
                              title: '提示框',
                              icon:0,
                          });
                      }
                  },
                  error:function (data){

                  }
              });

			  $('#Personal').find('.xinxi').removeClass("hover");
			  $('#Personal').find('.text_info').removeClass("add").attr("disabled", true);
			  $('#Personal').find('.btn-success').css({'display':'none'});
			   // layer.close(index);
			
		  }		  		
	};	
 //初始化宽度、高度    
    $(".admin_modify_style").height($(window).height()); 
	$(".recording_style").width($(window).width()-400); 
    //当文档窗口发生改变时 触发  
    $(window).resize(function(){
	$(".admin_modify_style").height($(window).height()); 
	$(".recording_style").width($(window).width()-400); 
  });
  //修改密码
  function change_Password(){
	   layer.open({
    type: 1,
	title:'修改密码',
	area: ['300px','300px'],
	shadeClose: true,
	content: $('#change_Pass'),
	btn:['确认修改'],
	yes:function(index, layero){		
		   if ($("#password").val()==""){
			  layer.alert('原密码不能为空!',{
              title: '提示框',				
				icon:0,
			    
			 });
			return false;
          } 
		  if ($("#Nes_pas").val()==""){
			  layer.alert('新密码不能为空!',{
              title: '提示框',				
				icon:0,
			    
			 });
			return false;
          } 
		   
		  if ($("#c_mew_pas").val()==""){
			  layer.alert('确认新密码不能为空!',{
              title: '提示框',				
				icon:0,
			    
			 });
			return false;
          }
        var reg1 = /([a-zA-Z0-9])/;  //密码验证
        // var reg2 = / {6,18} /;
		    if(!$("#c_mew_pas").val || $("#c_mew_pas").val() != $("#Nes_pas").val() )
        {
            layer.alert('密码不一致!',{
              title: '提示框',				
				icon:0,
			    
			 });
			 return false;
        } else if (!reg1.test($("#Nes_pas").val())){
                layer.alert('密码必须由数字和大小写字母!',{
                    title: '提示框',
                    icon:0,

                });
            }
		    // else if (!reg2.test($("#Nes_pas").val())){
            //     layer.alert('密码长度必须大于6!',{
            //         title: '提示框',
            //         icon:0,
            //
            //     });
            // }
		 else{
		     var oldPwd = $("#password").val();
		     var newPwd = $("#Nes_pas").val();
                $.ajax({
                    url: "http://localhost:8080/SnacksShop/supManager.do?type=updateSupManagerPwd",
                    type: "post",
                    data:{
                        oldPwd:oldPwd,
                        newPwd:newPwd
                    },
                    crossDomain: true,
                    xhrFields: {
                        withCredentials: true
                    },
                    type: "post",
                    success:function (data){
                        var obj = JSON.parse(data);
                        if (obj.status == '200'){
                            layer.alert('修改成功！',{
                                title: '提示框',
                                icon:1,
                            });
                            layer.close(index);
                        }else {
                            layer.alert('原密码错误！',{
                                title: '提示框',
                                icon:0,
                            });
                        }
                    },
                    error:function (data){

                    }
                });
		  }	 
	}
    });
	  }
</script>
<script>
jQuery(function($) {
		var oTable1 = $('#sample-table').dataTable( {
		"aaSorting": [[ 1, "desc" ]],//默认第几个排序
		"bStateSave": true,//状态保存
		"aoColumnDefs": [
		  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
		  {"orderable":false,"aTargets":[0,2,3,4,5,6]}// 制定列不参与排序
		] } );
				
				
				$('table th input:checkbox').on('click' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
						
				});
});

    var pageTotal;  //总页码
    var currentPage = 1;  //当前页码
    var upPage;     //上一页
    var nextPage;    //下一页
    function info(datas) {
        var tbodyChild = document.getElementById("infoTbody").childNodes;
        if (tbodyChild != null){
            $("#infoTbody").empty();
        }
        var nextPage = datas.nextPage;
        var infoDatas = datas.datas;
        for (i of infoDatas) {
            var tr = document.createElement("tr");
            tr.innerHTML = "<td>"+ i.manager.managerId + "</td>"+
                "<td>"+ i.manager.managerName + "</td>"+
                "<td>"+i.mangerLoggingText + "</td>"+
                "<td>"+ new Date(i.manager.manageTime.time).toLocaleDateString()+"</td>";
            $("#infoTbody").append(tr);
        }
    }
    var page = 1;
    function search(url,page) {
        $.ajax({
            url: url,
            type: "post",
            data:{
                currentPage:page,
                pageSize:10
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success:function (data){
                var obj = JSON.parse(data);
                if (obj.managerLoggings.message == '200'){
                    info(obj.managerLoggings.object);
                    var object = obj.managerLoggings.object;
                    currentPage = object.currentPage;
                    $("#page").val(currentPage);
                    $("#total").val(obj.managerLoggings.object.totalPage);
                    nextPage = object.nextPage;
                    upPage = object.upPage;
                    pageTotal = object.totalPage;
                    btnDisabled(object);
                }
            },
            error:function (data){

            }
        });
    };
    var url = "http://localhost:8080/SnacksShop/supManager.do?type=querySupManagerLogging";
    search(url,1);
    //判断按钮是否禁用
    function btnDisabled(object) {
    var currentPage = object.currentPage;
    var upPage = object.upPage;
    var nextPage = object.nextPage;
    var upElement = $("#upPage");
    var nextElement = $("#nextPage");
    if (currentPage == upPage){
        upElement.attr("disabled",true);
    }else {
        upElement.attr("disabled",false);
    }
    if (currentPage == nextPage){
        nextElement.attr("disabled",true);
    }else {
        nextElement.attr("disabled",false);
    }
}
    //上一页
    function up() {
        var upPage = parseInt($("#page").val()) - 1;
        // var url = "http://localhost:8080/SnacksShop/supManager.do?type=querySupManagerLogging";
        search(url,upPage);
    };

    //下一页
    function next() {
        var nextPage = parseInt($("#page").val()) + 1;
        // var url = "http://localhost:8080/SnacksShop/supManager.do?type=querySupManagerLogging";
        search(url,nextPage)

    };
var pageText = $("#page");
//数字框的回车
    document.getElementById("page").addEventListener("keyup",function (event) {
    event.preventDefault();
    if (event.keyCode === 13){
        var values = pageText.val();
        if (isNaN(values)){
            alert("不是数字");
            $("#page").val(currentPage);
        }else {
            if (values > pageTotal){
                $("#page").val(currentPage);
                alert("没有了");
            }else {
                var currentPageTemp = $("#page").val();
                // var url = "http://localhost:8080/SnacksShop/supManager.do?type=queryAllLogging";
                search(url,currentPageTemp);
            }
        }
    }
});
function verifyInfo(type,info,errorText,element) {
        $.ajax({
            url: "http://localhost:8080/SnacksShop/supManager.do?type=verifySupInfo&verifyType="+type,
            type: "post",
            data:{
                verifyInfo:info
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success:function (data){
                var obj = JSON.parse(data);
                if (obj.result){
                    layer.alert(errorText+"已存在！\r\n",{
                        title: '提示框',
                        icon:0,
                    });
                    element.attr("value",true);
                }else {
                    element.attr("value",false);
                }
            },
            error:function (data){

            }
        });
    }
    //验证修改之后的用户名是否存在
    document.getElementById("website-title").addEventListener("blur",function (){
        var username = $("#website-title").val();
        var type = "name";
        var errorText = "用户";
        verifyInfo(type,username,errorText,$("#website-title"));
    });
    document.getElementById("iphone").addEventListener("blur",function (){
        var iphone = $("#iphone").val();
        var pattern = /^1\d{10}$/;
        if (pattern.test(iphone)){
            verifyInfo("iphone",iphone,"手机号码",$("#iphone"));
        }else {
            layer.alert("手机号码有误 \r\n",{
                title: '提示框',
                icon:0,
            });
        }
    });
    document.getElementById("email").addEventListener("blur",function (){
        var email = $("#email").val();
        var pattern = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/g;
        if (pattern.test(email)){
            verifyInfo("email",email,"邮箱",$("#email"));
        }else {
            layer.alert("邮箱有误 \r\n",{
                title: '提示框',
                icon:0,
            });
        }
    });




    //disabled属性设置不了
    /*document.getElementById("saveBox").addEventListener("mouseover",function (){
        var usernameExist = $("#website-title").attr("value");
        var iphoneExist = $("#iphone").attr("value");
        var emailExist = $("#email").attr("value");
        if (usernameExist == 'true'|| iphoneExist == 'true' || emailExist == 'true'){
            document.getElementById("saveBtn").disabled = true;
            console.log("手机号码:"+iphoneExist);
        }else {
            // $("#saveBtn").attr("disabled",false);
            document.getElementById("saveBtn").disabled = false;
        }
    });
    document.getElementById("saveBox").addEventListener("mouseover",function (){
        document.getElementById("saveBtn").disabled = false;
    });*/
</script>
